package com.shengde.jinwawaforleader.model.myJob.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.shengde.jinwawaforleader.R;
import com.shengde.jinwawaforleader.model.myJob.teachResource.MingshiDetailActivity;
import com.shengde.jinwawaforleader.network.protocolbean.ProBookList;

import java.util.List;


public class MingshiAdapter extends BaseAdapter {

	protected Context context;
	public List<ProBookList.BooklistEntity> list;

	public MingshiAdapter(List<ProBookList.BooklistEntity> list,
						  Context context) {
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		if (list == null || list.size() <= 0) {
			return convertView;
		}
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_fragment_two_mingshi, parent, false);
			holder.image = (ImageView) convertView.findViewById(R.id.image);
			holder.title = (TextView) convertView.findViewById(R.id.title);
			holder.describe = (TextView) convertView
					.findViewById(R.id.describe);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		Glide.with(context).load(list.get(position).getCover()).error(R.drawable.iconfont_wodekecheng).into(holder.image);
		holder.title.setText(list.get(position).getName());
		holder.describe.setText(list.get(position).getDesc());
		convertView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent aa = new Intent();
				aa.setClass(context, MingshiDetailActivity.class);
				aa.putExtra("id", list.get(position).getId());
				aa.putExtra("name", list.get(position).getName());
				context.startActivity(aa);
			}
		});

		return convertView;
	}

	protected final class ViewHolder {

		public LinearLayout show_detail;
		public ImageView image;
		public TextView title;
		public TextView describe;

	}

}
